#include "my_timer.h"
#include "ui_my_timer.h"
#include <QDebug>

my_timer::my_timer(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::my_timer)
{
    ui->setupUi(this);
    time.setHMS(0,0,0,0);
    mingci = 0;
    ui->LB_timer->setText("00:00:00:000");
}

my_timer::~my_timer()
{
    delete ui;
}


void my_timer::on_PD_start_clicked()
{
    if(timer.isActive())
    {
        QMessageBox::information(this, "警告","定时器已经打开！");
    }
    else
    {
        connect(&timer, SIGNAL(timeout()), this, SLOT(slot_timer_out()));
        timer.start(50);
    }
}
void my_timer::slot_timer_out(void)
{
    time = time.addMSecs(50);
    ui->LB_timer->setText(time.toString("hh:mm:ss.zzz"));
}

void my_timer::on_PD_stop_clicked()
{
    if(timer.isActive())
    {
        timer.stop();
    }
    else
    {
        QMessageBox::information(this, "警告","定时器已经关闭！");
    }
}

void my_timer::on_PD_reset_clicked()
{
    time.setHMS(0,0,0,0);
    ui->LB_timer->setText("00:00:00:000");
    ui->PTE_show->clear();
    mingci = 0;
    timer.stop();
}

void my_timer::on_PD_bit_clicked()
{
    if(timer.isActive())
    {
        QString temp;
        mingci ++;

        temp.sprintf("第%d名：  ", mingci);

        ui->PTE_show->appendPlainText(temp);
        ui->PTE_show->appendPlainText(time.toString("hh:mm:ss.zzz"));
    }
    else
    {
        QMessageBox::information(this, "警告","请点击开始再打表！");
    }
}
